package com.bracketbird.server.services;

import com.bracketbird.client.model.*;
import com.bracketbird.client.service.rtc.*;
import com.bracketbird.server.dao.*;
import com.bracketbird.server.repository.*;
import com.google.appengine.api.channel.*;
import com.bracketbird.clientcore.appcontrol.*;
import com.bracketbird.clientcore.model.keys.*;


/**
 *
 */
public class RTCCreateChannelHandler extends AbstractActionHandler implements ActionHandler<CreateChannelTokenAction, CreateChannelTokenResult> {


    public CreateChannelTokenResult execute(CreateChannelTokenAction action) throws ApplicationException {

        TournamentChannelRepository tCRep = new TournamentChannelRepository();

        try {

            UserId userId = action.getUserId();
            CreateTournamentChannel creater = new CreateTournamentChannel();

              ChannelService channelService = ChannelServiceFactory.getChannelService();
             //channelService.createChannel()
             //channelService.sendMessage(new ChannelMessage());

              String token = channelService.createChannel(userId.getEncodedKey() + System.currentTimeMillis());

            return new CreateChannelTokenResult(token);
        }
        finally {
            PMF.endTransaction();
        }
    }

    public Class<CreateChannelTokenAction> getActionType() {
        return CreateChannelTokenAction.class;
    }


}